package mesh

import (
	"context"
	v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/apimachinery/pkg/runtime"
	"k8s.io/apimachinery/pkg/watch"
	"k8s.io/client-go/dynamic"
	"k8s.io/client-go/tools/cache"
)

func NewListWatchMeshFromClient(ctx context.Context, client dynamic.Interface) *cache.ListWatch {
	listFunc := func(options v1.ListOptions) (runtime.Object, error) {
		return client.Resource(Schema).List(ctx, v1.ListOptions{})
	}
	watchFunc := func(options v1.ListOptions) (watch.Interface, error) {
		return client.Resource(Schema).Watch(ctx, v1.ListOptions{})
	}

	return &cache.ListWatch{ListFunc: listFunc, WatchFunc: watchFunc}
}
